<!DOCTYPE html>
<html lang="en">
<script src="js/jquery-1.10.2.min.js"></script>
<link rel="stylesheet" href="css/bootstrap.min.css">
<script src="js/bootstrap.min.js"></script>
<script src="js/common.js"></script>
<script src="js/user.js"></script>

<style>
    .panel{width:60%;margin:0 auto;text-align: center;}
    .form-inline{width:60%;margin:0 auto;}
</style>
<head>
    <meta charset="UTF-8">
    <title>整体架构</title>
</head>
<body>
<nav class="navbar navbar-default">
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
            <a class="navbar-brand" href="#">心理咨询预约系统</a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav">
                <!--<li><a href="#">Link</a></li>-->
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" id="UserID">
                        <script type="text/javascript">
                            $(function() {
                                $.ajax({
                                    url: "online",
                                    type: "GET",
                                    success: function(response) {
                                        if(response!=null) {
                                            $("#UserID").append(response.toString()
                                                + '<b class="caret"></b>');
                                        }
                                    },
                                    error: function(xhr, msg, e) {
                                        alert("error!");
                                    }
                                });
                            });

                        </script>
                    </a>
                    <ul class="dropdown-menu">
                        <li><a data-toggle="modal" data-target="#changepw" href="#" >修改密码</a></li>
                        <li><a href="reservation.html">我的预约</a></li>
                        <li><a href="index.html" onclick="logout()">登出</a></li>
                    </ul>
                </li>
            </ul>
            <div class="navbar-form navbar-left">
                <div class="form-group">
                    <input type="text" class="form-control" placeholder="Search" id="searchTxt">
                </div>
                <button type="submit" class="btn btn-default" id="search_bt" onclick="search()">Search</button>
            </div>
        </div><!-- /.navbar-collapse -->
    </div><!-- /.container-fluid -->
</nav>


<div class="panel panel-default">
    <div class="panel-heading">

    </div>
    <table class="table" id="postTable">
        <tr style="font-weight: bold"><td>工号</td><td>姓名</td><td>地点</td><td>值班日</td><td>人数</td></tr>
        <!--<tr><td>算法导论</td><td>Thomas</td><td>机械工业出版社</td><td>已借</td></tr>-->
        <!--<tr><td>产品 B</td><td>400</td></tr>-->
        <script type="text/javascript">
            $(function() {
                $.ajax({
                    url: "showAll",
                    type: "GET",
                    success: function(response) {
                        $.each(response, function(i, item) {
                            $("#postTable").append(
                                '<tr><td>'+item.tno+'</td><td>'+item.tname+'</td><td>'+item.location+'</td><td>'+item.dutytime+'</td><td>'+item.currentnumber+'/'+item.totalnumber+'</td>'+'<td><a class="btn btn-primary btn-xs" role="button" href="#" id="'+item.tno+'" onclick="reserve_tno(this)" >预约</a></td></tr>');
                        });
                    },
                    error: function(xhr, msg, e) {
                        alert("error!");
                    }
                });
            });

            function reserve_tno(obj) {
                var data={};
                console.log(obj.id);

                data["tno"]=obj.id.toString();
                console.log(data["tno"]);
                if(confirm("请您确认预约信息？")){
                    $.ajax({
                        url:"createAppointment",
                        type: "POST",
                        data:data,
                        dataType:"JSON",
                        success: function (response) {
                            if(response.error_code === 1) {
                                setTimeout('window.location.href="reservation.html"');
                                alert(response.error_message);
                            }
                            else{
                                setTimeout('window.location.href="home.html"');
                                alert(response.error_message);
                            }
                        },
                        error: function(xhr, msg, e) {
                            console.log(e);
                        }

                    });
                }
            }

            function changepw() {
                var data={};

                var oldpw = document.getElementById('oldpw');
                var newpw = document.getElementById("newpw");
                data["oldpw"] = oldpw.value;
                data["newpw"] = newpw.value;
                $.ajax({
                        url:"changepw",
                        type: "POST",
                        data:data,
                        async:false ,
                        dataType:"JSON",
                        success: function (response) {
                            if(response.error_code === 1) {
                                window.location.href="index.html";
                            }
                            else{
                                alert(response.error_message);
                            }
                        },
                        error: function(xhr, msg, e) {
                            setTimeout('window.location.href="index.html"');
                        }

                    });
            }

        </script>
    </table>
</div>


<!-- 登录窗口 -->
<div id="changepw" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-body">
                <button class="close" data-dismiss="modal">
                    <span>&times;</span>
                </button>
            </div>
            <div class="modal-title">
                <h2 class="text-center">修改密码</h2>
            </div>
            <div class="modal-body">
                <form class="form-group" action="">
                    <div class="form-group">
                        <label for="">旧密码</label>
                        <input id="oldpw" class="form-control" type="password" placeholder="">
                    </div>
                    <div class="form-group">
                        <label for="">新密码</label>
                        <input id="newpw" class="form-control" type="password" placeholder="">
                    </div>
                    <div class="text-right">
                        <button class="btn btn-primary" type="submit" id="change" onclick="changepw()">确认</button>
                        <button class="btn btn-danger" data-dismiss="modal">取消</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>


</body>

</html>
